package com.jt.controller;

import com.jt.mapper.UserMapper;
import com.jt.pojo.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

//@RestController-->程序将不会执行视图解析器
@Controller
public class UserController {
    @Autowired
    private UserMapper userMapper;
    @RequestMapping("/findAll")
    public String FindAll(Model model){
        List<Users> list = userMapper.findAll();
        model.addAttribute("userList",list);

        return "userList";
    }
    /*
    接受ajax请求
    返回list<User>
     */
    @RequestMapping("/toAjax")
    public String toAjax(){

        return "ajax";
    }
    @RequestMapping("/findAjax")
    @ResponseBody//因为返回的json串，自动将对象转换为json
    public List<Users> findAjax(){
        List<Users> ajaxlist = userMapper.findAll();
        return ajaxlist;
    }

}
//上面是同步的方法，下面是异步的方法
/*
跳转到ajax页面
 */

